import request from '@/utils/request'

export const getUuid = () => {
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";

  var uuid = s.join("");
  return uuid;
}

// 登录
export function loginApi (data) {
  return request('/api/session/login', {
    method: 'POST',
    data
  });
}
  // 登出
export function logoutApi(token) {
  return request(`/api/session/logOut?x-access-token=${token}`, {
    method: 'GET'
  });
}

//任务列表
export function taskList (data) {
  return request('/api/task/page/query', {
    method: 'POST',
    data
  });
}

export function taskInfo (data) {
  return request('/api/subtask/page/query', {
    method: 'POST',
    data
  });
}
export function subtaskExecute (data) {
  return request('/api/task/'+data.taskId+'/subtask/'+data.subtaskId+'/execute', {
    method: 'POST',
    data
  });
}

export function getAllDefectType () {
  return request('/api/defectType/groupList', {
    method: 'POST',
  });
}

/**
 * 根据环节查询缺陷类型
 * @param {*} data 
 * @returns 
 */
export function getDefectTypeByTaskNode (data) {
  return request('/api/defectType/list', {
    method: 'POST',
    data: data
  });
}

export function uploadFiles (data) {
  return request('/api/file/localUpload/'+ data.moduleType + '/' + data.taskCode, {
    method: 'POST',
    data:data.fileData
  });
}
export function nextSave (data) {
  return request('/api/subTaskNodeInst/next', {
    method: 'POST',
    data
  });
}
//挂起任务
export function hangSubTaskNode (data){
  return request('/api/task/subtask/hang', {
    method: 'POST',
    data
  });
}
// 跳过环节
export function skipSubTaskNode (data) {
  return request('/api/subTaskNodeInst/' + data.subtaskId + '/' + data.taskNodeInstId + '/skip', {
    method: 'POST'
  });
}

export function preData (data) {
  return request('/api/subTaskNodeInst/'+data.subtaskId+'/'+data.taskNodeInstId+'/prev', {
    method: 'POST'
  });
}

//获取当前节点数据
export function getCurrentNodeInfo (data) {
  return request('/api/subTaskNodeInst/'+data.subtaskId+'/'+data.taskNodeInstId+'/query', {
    method: 'POST',
    data
  });
}
export function finishTask(data){
  return request('/api/' + data.subTaskId + '/' + data.taskNodeInstId  + '/finish', {
    method: 'POST',
  });
}
//获取子任务详情
export function getSubTaskInfo(subTaskId){
  return request('/api/subTask/'+subTaskId, {
    method: 'POST',
  });
}

//删除附件
export function deleteTaskNodeFile(data) {
  return request('/api/subTaskNodeInst/delete', {
    method: 'POST',
    data
  });
}

// 清空子任务
export function resetSubTask(data) {
  return request('/api/task/' + data.subTaskId + '/reset', {
    method: 'POST'
  });
}

// 获取子任务附件
export function getTaskNodeFileList(data) {
  return request('/api/subTaskNodeInst/' + data.subTaskNodeInstId + '/' + data.processConfigId + '/file', {
    method: 'POST'
  });
}

// 获取电芯型号
export function getElectricCoreTypeList() {
  return request('/api/electricConfig/queryElectricType', {
    method: 'GET'
  });
}

// 获取电芯类型
export function getCellTypeList() {
  return request('/api/electricConfig/queryCellType', {
    method: 'GET'
  });
}

// 获取工厂配置
export function getFactoryList() {
  return request('/api/electricConfig/queryFactory', {
    method: 'GET'
  });
}

// 获取动态配置的表单元素
export function getDynamicConfigElementList() {
  return request('/api/taskProcessConfig/dynamicElementList', {
    method: 'POST'
  })
}

// 删除动态元素
export function deleteDynamicConfigElement(id) {
  return request('/api/nodeInstProcessRelation/delete/' + id, {
    method: 'POST'
  })
}

// 获取AI接口极组附件
export function getSubTaskPoleGroupFilesFromAI(data) {
  return request('/api/subTaskNodeInst/interface/file', {
    method: 'POST',
    data
  })
}

// 获取极组附件
export function getSubTaskPoleGroupFiles(data) {
  return request('/api/subTaskNodeInst/file', {
    method: 'POST',
    data
  })
}

